﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Windows.Automation;


namespace PokerStarsClientTools
{
    /// <summary>
    /// Class representing the main PokerStars Client Windows
    /// </summary>
    public class MainPSWindow
    {

        private string WindowTitleStart = "PokerStars Lobby - Logged in as Stef2001";

        
        private AutomationElement _PsWindowsUI;
        /// <summary>
        /// The Main PokerStarts Client Window
        /// </summary>
        public AutomationElement PsWindowsUI
        {
            get { return _PsWindowsUI; }
        }


       
        /// <summary>
        /// The Register Button of the Lobby
        /// </summary>
        public PsLobbyRegisterButton LobbyRegisterButton { 
            get 
            {                
                return new PsLobbyRegisterButton(PsWindowsUI);
            }
        }





        /// <summary>
        /// The Register Button is visible and activated
        /// </summary>
        public Boolean IsRegisterButtonClickable { get { return LobbyRegisterButton.IsClickable; } }


        /// <summary>
        /// The Current Tourney list of the Lobby
        /// </summary>
        public PSLobbyTourneyList  LobbyTourneyList
        {
            get
            {
                return new PSLobbyTourneyList(PsWindowsUI);
            }
        }

        public MainPSWindow(string WindowsMainTitleStart)
        {
            WindowTitleStart = WindowsMainTitleStart;
            InitialiseMainPSWindow();
        }

        /// <summary>
        /// Contructor that wil try to connect to the main Pokerstars Client
        /// </summary>
        private  void InitialiseMainPSWindow()
        {
           
            AutomationElement ps = UIAutomationTools.GetElement(AutomationElement.RootElement  ,WindowTitleStart , false);

            if(ps==null)
                throw new Exception("Main Client Window Not Found");


            _PsWindowsUI = ps;


        }


        
    }


    /// <summary>
    /// Represent the Register button of the lobby window
    /// </summary>
    public class PsLobbyRegisterButton
    {

        const string RegisterText = "Register";
        const string ClassName = "PokerStarsButtonClass";

        private AutomationElement _Button;

        /// <summary>
        /// The Button is clicabkle (visible and enabled)
        /// </summary>
        public Boolean IsClickable { get { return _Button!=null;} }

        /// <summary>
        /// Constructeor of the class
        /// </summary>
        /// <param name="PsWindow">The PokerStars Main Windows</param>
        public PsLobbyRegisterButton(AutomationElement PsWindow)
        {
            _Button = UIAutomationTools.GetElement(PsWindow, "Register", false);
            //AutomationElementCollection colbutton = UIAutomationTools.GetElementsByClassName(PsWindow, ClassName, false);

        }


    }

    /// <summary>
    /// Represent the current tourney list visible in the Lobby (the liste of tourney take count of the tourneys filter)
    /// </summary>
    public class PSLobbyTourneyList
    {
        const string TourneyListText = "";
        const string ClassName = "PokerStarsListClass";

        private AutomationElement _TourneyList;

        /// <summary>
        /// Constructeor of the class
        /// </summary>
        /// <param name="PsWindow">The PokerStars Main Windows</param>
        public PSLobbyTourneyList(AutomationElement PsWindow)
        {
            AutomationElementCollection listes = UIAutomationTools.GetElementsByClassName(PsWindow, ClassName, false);

            _TourneyList = listes[0];

            //UIAutomationTools.WalkEnabledElements(PsWindow);

            System.Windows.Point clickablepoint = _TourneyList.GetClickablePoint();

            

        }


    }


}
